import sys
import os
import re
import subprocess
import time

# 将指令封装到字典中
command_dic = {"shutScreen": 'adb shell input keyevent 26',  # 关闭屏幕指令
               "awakenScreen": "adb shell input keyevent 224",  # 唤醒屏幕指令
               "swipe_left": "adb shell input swipe 700 700 200 700 ",  # 左滑屏
               "swipe_right": "adb shell input swipe 200 700 700 700 ",  # 右滑屏
               "click_choice1": "adb shell input tap 500 900",  # 单击 下同 下下同
               "click_choice2": "adb shell input tap 600 1100",
               "click_choice3": "adb shell input tap 500 1200",
               "click_ok": "adb shell input  tap 600 1800",
               "click_submit": "adb shell input keyevent 224",
               "click_stop": "adb shell input keyevent 224",
               "": "adb shell input keyevent 224", }
time_gap = 1;


def test():
    # 连接手机
    # os.system('adb shell input keyevent 26')
    # os.system(command_dic['shutScreen'])
    for i in range(0, 100):
        os.system(command_dic['click_choice1'])
        os.system(command_dic['click_choice2'])
        os.system(command_dic['click_choice3'])
        os.system(command_dic['click_ok'])
        time.sleep(time_gap)
        os.system(command_dic['swipe_left'])

    # # coding:utf-8
    # # 缺点：运行时不能移动屏幕，后续可以采用获取模块ID号的方式去点击相应的位置
    # i = 0
    # # 每次操作的间隔时间取决于手机配置，配置越高时间越短
    # sleep_time = 0.5
    # while 1:
    #     # 用popen设置shell=True不会弹出cmd框
    #     process = subprocess.Popen('adb shell input tap 14 1402', shell=True)
    #     time.sleep(sleep_time)
    #     process = subprocess.Popen('adb shell input keyevent KEYCODE_BACK', shell=True)
    #     time.sleep(sleep_time)
    #     process = subprocess.Popen('adb shell input tap 375 1402', shell=True)
    #     time.sleep(sleep_time)
    #     process = subprocess.Popen('adb shell input keyevent KEYCODE_BACK', shell=True)
    #     time.sleep(sleep_time)
    #     # os.system('adb shell input tap 14 1402')
    #     # os.system('adb shell input keyevent KEYCODE_BACK')
    #     # os.system('adb shell input tap 375 1402')
    #     i += 1
    #     print
    #     str(i) + 'clicks have been completed'


if __name__ == '__main__':
    test()
